// axios封装模块

import axios from "axios";

const server = axios.create({
  baseURL: "/api",
  timeout: 60000,
});

// 请求拦截器
server.interceptors.request.use((request) => {
  // const token = sessionStorage.getItem("token");
  // if (token) {
  //   request.headers["Authorization"] = token;
  // }

  return request;
});

// 响应拦截器
server.interceptors.response.use((response) => {
  return response.data;
});

function request({
  url,
  method = "get",
  headers = {},
  params = {},
  data = {},
  controller,
}) {
  const signal = controller ? controller.signal : undefined;
  return server({
    url,
    method,
    headers,
    params,
    data,
    signal,
  });
}

export default request;
